require (['./config'], () => {
    require(['template','header','footer','bootstrap'], (template,header) => {
        class Products {
            constructor () {
                this.getlist()
                this.page()
            }
            getlist(){
                $.get('http://rap2api.taobao.org/app/mock/241299/example/1577704916579',resp=>{
                    if (resp.code === 200) {
                        const { list } = resp.body
                        this.renderType(list)
                        const _this =this
                        $('#select').bind('change',function(){
                            if(this.value=='down'){
                              list.sort(function(a,b){
                                 return (b.price-a.price)
                               })
                               console.log(list);  
                               _this.renderType(list)
                            }
                            if(this.value=='up'){
                              list.sort(function(a,b){
                                 return (a.price-b.price)
                               })
                               console.log(list);
                               _this.renderType(list) 
                           }     
                         }) 
                    }
                })
             }
             renderType(list) {
                $('#goodsList').html(template('categoryTempalte', { list }))
        
              }
              page(){
                $('#fenye1,#fenye2,#fenye3,#fenye4').on('click',(e)=>{
                  this.getlist()
                })
              }
            
        }
        new Products()
    })
})